<template>
    <div class="test">
        <remote-css href="http://at.alicdn.com/t/font_1922582_r2jx2fx1nz.css"></remote-css>
        <div class="btns">
            <el-button class="iconfont icon-icon-test" size="small" type="primary" @click="toAdd" circle></el-button>
        </div>
        <el-table :data="list" size="small" style="width: 100%">
            <el-table-column type="index" label="序号"></el-table-column>
            <el-table-column prop="id" label="文章uid"></el-table-column>
            <el-table-column prop="title" label="标题" :show-overflow-tooltip="true"></el-table-column>
            <el-table-column prop="content" label="内容" :show-overflow-tooltip="true"></el-table-column>
            <el-table-column prop="publishDate" label="发布日期"></el-table-column>
            <el-table-column prop="readTimes" label="阅读次数"></el-table-column>
            <el-table-column prop="thumbUpTimes" label="点赞"></el-table-column>
            <el-table-column prop="thumbDownTimes" label="被踩"></el-table-column>
            <el-table-column prop="status" label="状态"></el-table-column>
            <el-table-column prop="categoryId" v-if="false"></el-table-column>
            <el-table-column prop="userId" v-if="false"></el-table-column>
            <el-table-column prop="categoryName" label="所属栏目"></el-table-column>
            <el-table-column prop="username" label="发布者"></el-table-column>
            <el-table-column label="操作" width="150px" align="center">
                <template v-slot="scope">
                    <el-button size="small" type="primary" @click="edit(scope.row)">修改</el-button>
                    <el-button size="small" type="danger" @click="del(scope.row)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-dialog class="customer_modal" title="提示" :visible.sync="dialogVisible" width="60%" :before-close="handleClose">
            <el-form :model="form" label-width="100px">
                <el-form-item label="标题">
                    <el-input v-model="form.title"></el-input>
                </el-form-item>
                <el-form-item label="内容">
                    <el-input v-model="form.content"></el-input>
                </el-form-item>
                <el-form-item label="发布日期">
                    <el-input v-model="form.publishDate"></el-input>
                </el-form-item>
                <el-form-item label="阅读次数">
                    <el-input v-model="form.readTimes"></el-input>
                </el-form-item>
                <el-form-item label="点赞">
                    <el-input v-model="form.thumbUpTimes"></el-input>
                </el-form-item>
                <el-form-item label="被踩">
                    <el-input v-model="form.thumbDownTimes"></el-input>
                </el-form-item>
                <el-form-item label="状态">
                    <el-input v-model="form.status"></el-input>
                </el-form-item>
                <el-form-item label="所属栏目">
                    <el-input v-model="form.categoryId"></el-input>
                </el-form-item>
                <el-form-item label="发布者">
                    <el-input v-model="form.userId"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible = false" size="small">取 消</el-button>
                <el-button type="primary" @click="save" size="small">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>
<script>
import {get, post} from '@/utils/request'
export default{
    components:{
       'remote-css': {
            render(createElement) {            
              return createElement('link', { attrs: { rel: 'stylesheet', href: this.href }});
            },
            props: {
                href: { type: String, required: true },
            },
        },
        'remote-js': {
            render(createElement) {
              return createElement('script', { attrs: { type: 'text/javascript', src: this.src }});            
            },
            props: {
                src: { type: String, required: true },
            },
        },
    },
    data() {
        return {
            form: {},
            list: [],
            dialogVisible: false
        }
    },
    created() {
        this.loadData();
    },
    methods: {
        save() {
            let url = "/article/saveOrUpdate";
            post(url, this.form).then((response) => {
                this.dialogVisible = false;
                this.$message({type:"success", message:response.message});
                this.loadData();
            });
            this.form = {};
        },
        del(row) {
            this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                let url = "/article/deleteById";
                get(url, {id:row.id}).then((response) => {
                    this.$message({type:"success", message:response.message});
                    this.loadData();
                });
            })
        },
        edit(row) {
            this.form = JSON.parse(JSON.stringify(row));
            this.dialogVisible = true;
        },
        loadData() {
            let url = "/article/findAll";
            get(url).then((response) => {
                this.list = response.data;
            });
        },
        toAdd() {
            this.dialogVisible = true
        }
    }
}
</script>

<style scoped>

</style>
